/*******************************************************************************
DebugLog.cpp

Notes:
*******************************************************************************/

#include "DebugLog.h"

// Initialize the DebugLog instance to NULL
DebugLog* DebugLog::m_pLog = NULL;

//  GetLog(void)
//      Returns the instance of DebugLog. Mainaints singularity.
DebugLog* DebugLog::GetLog(void)
{
    // If the DebugLog instance has not been created...
    if(m_pLog == NULL)
    {
        // ... create a new DebugLog and initialize it
        m_pLog = new DebugLog();
        m_pLog->Init();
    } // if(m_pLog == NULL)

    // Return the instance of DebugLog
    return m_pLog;
} // GetLog(void)

//  Init(void)
//      Opens a file for the DebugLog instance to write to
void DebugLog::Init(void)
{
    // Create and open debug.log for writing
    m_file.open("debug.log", std::ios::out | std::ios::app);
} // Init(void)

//  Write(char* szMessage)
//      Writes szMessage to the log file
void DebugLog::Write(std::string strMessage)
{
    // If our file is not open...
    if(!m_file.is_open())
    {
        // ... initialize the DebugLog (opens the file)
        Init();
    } // if(!m_file.is_open())

    // If there was not a problem opening the file...
    if(m_file.is_open())
    {
        // ... write szMessage and a '\n' to the file
        m_file << strMessage << std::endl;
    } // if(m_file.is_open())
} // Write(char* szMessage)
